package coom.etc.controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.etc.entity.Emp;
import com.etc.service.EmpService;
import com.etc.serviceImpl.EmpServiceImpl;
import com.etc.util.PageData;

/**
 * Servlet implementation class EmpServlet
 */
@WebServlet("/es")
public class EmpServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public EmpServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("utf-8");
		String op=request.getParameter("op");
		EmpService es=new EmpServiceImpl();
		
		int page=1;
		int pageSize=10;
		if(request.getParameter("page")!=null) {
			page=Integer.parseInt(request.getParameter("page"));
		}
		
		if(request.getParameter("pageSize")!=null) {
			pageSize=Integer.parseInt(request.getParameter("pageSize"));
		}
		String key="";
		if(request.getParameter("key")!=null) {
			key=request.getParameter("key");
		}
		if("queryByPage".equals(op)) {
			PageData<Emp> pd=es.queryEmpByPage(page, pageSize,key);
			request.setAttribute("pd", pd);
			request.setAttribute("key", key);
			request.getRequestDispatcher("emp.jsp").forward(request, response);
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
